package com.yc.ioc.bean4_ioc_import;

import com.yc.ioc.bean4_ioc_import.other.Apple;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author zwei
 * @create 2024-07-29 8:52
 */
public class AppleImportBeanDefinitionRegistar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        //将要导入的类的类名首字母小写后缀为  beanid
        System.out.println(importingClassMetadata);
        System.out.println(registry);
        boolean b=registry.containsBeanDefinition(Apple.class.getName());
        String beanid=Apple.class.getSimpleName().substring(0,1).toLowerCase()+
                Apple.class.getSimpleName().substring(1);
        if (b==false){
            //bean的定义信息对象
            //spring对bean的扫描和加载流程  先扫描bean-》先创建BeanDefition对象-》再创建对象-》考虑依赖的顺序
            RootBeanDefinition bd=new RootBeanDefinition(Apple.class);
            registry.registerBeanDefinition(beanid,bd);
        }
    }
}
